package common.harvin.potocol;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;

public final class Response implements Serializable {
	//反应针对的命令
	private Command for_command;
	//the number of the sender.
	private String sender;
	//the number of the receiver
	private String receiver;
	//返回的结果
	private boolean result = false;
	//返回的数据
	private HashMap<String, String> data = new HashMap<String, String>();
	//客户端发送信息的时间
	private Date send_Date;
	//服务端反应时间
	private Date respone_Date;

	public Response() {
		this.setRespone_Date();
	}

	public Response(Request request) {
		this.for_command = request.getCommand();
		this.send_Date = request.getSend_Date();
		this.setRespone_Date();
	}

	/**
	 * this function will clear the data in data field,
	 * the for_command and send_Date;
	 * but reset the result and respone_Date as default.
	 */
	public void reset() {
		this.data.clear();
		this.for_command = null;
		this.result = false;
		this.send_Date = null;
		this.respone_Date = new Date();
	}

	public Command getFor_command() {
		return for_command;
	}

	public void setFor_command(Command for_command) {
		this.for_command = for_command;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}
	
	public boolean isResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public String getData(String key) {
		return data.get(key);
	}

	public void addData(String key, String value) {
		this.data.put(key, value);
	}

	public Date getSend_Date() {
		return send_Date;
	}

	public void setSend_Date(Date send_Date) {
		this.send_Date = send_Date;
	}

	public Date getRespone_Date() {
		return respone_Date;
	}

	public void setRespone_Date() {
		this.respone_Date = new Date();
	}
}
